/*
	YoghurtGum - 2D Game Engine

	Copyright 2009-2011 Quinten Lansu
	
	Licensed under the Apache License, Version 2.0 (the "License"); you may not 
	use this file except in compliance with the License. You may obtain a copy 
	of the License at 
		
		http://www.apache.org/licenses/LICENSE-2.0 
		
	Unless required by applicable law or agreed to in writing, software 
	distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 
	WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 
	License for the specific language governing permissions and limitations 
	under the License. 
*/

#ifndef _YGDATE_H_
#define _YGDATE_H_

#include "YGSources.h"

#if (YG_OS_TYPE == YG_OS_TYPE_ANDROID)

	#define YG_TIMECONTAINER     struct timeval

#elif (YG_OS_TYPE == YG_OS_TYPE_WINDOWSMOBILE)

	#define YG_TIMECONTAINER     SYSTEMTIME

#elif (YG_OS_TYPE == YG_OS_TYPE_BADA)

	//typedef int YG_TIME_CONTAINER;
	#define YG_TIMECONTAINER     int

#endif

const int SECONDS_IN_DAY = 24 * 60 * 60;
#define LEAPYEAR(year)    (!((year) % 4) && (((year) % 100) || !((year) % 400)))

namespace YoghurtGum
{

	struct Date
	{
		/*
			Converts a 32-bit number of seconds after 01-01-1970 to a _SYSTEMTIME structure
		*/
		static YG_TIMECONTAINER Convert(time_t a_UnixTime);

		/*
			Supports the following formats:

			$h		= 24 hour format hour
			$hh		= 24 hour format hour, with trailing zeros
			$H		= 12 hour format hour
			$HH		= 12 hour format hour, with trailing zeros
			$n		= minutes
			$nn		= minutes, with trailing zeros
			$s		= seconds
			$ss		= seconds, with trailing zeros

			$d		= day of month
			$dd		= day of month, with trailing zeros
			$m		= month
			$mm		= month, with trailing zeros
			$yy		= last two digits of year
			$yyyy	= four digit year

			$time	= digital time (hh:nn)
			$TIME	= digital time (hh:nn:ss)
			$clock	= analog 12-hour time (HH:nn AM/PM)
			$CLOCK	= analog 12-hour time (HH:nn:ss AM/PM)
			$iso	= ISO 8601 international standard (yyyy-mm-dd)
			$le		= little endian (dd-mm-yyyy)
			$be		= big endian (yyyy-MM-dd)
			$me		= middle endian (mm/dd/yy)
		*/
		static char* Format(const char* a_Format, time_t a_UnixTime = 0);

		static void AddNumber(int a_Number);

		/*
			Outputs every option to see if there's something wrong with the Format function.
		*/
		static char* UnitTest()
		{
			Format("Testing: $h $hh $n $nn $s $ss - $d $dd $m $mm $M $MM $yy $yyyy | $clock | $CLOCK | $time | $TIME | $le | $be | $me | $iso");
			return s_Output;
		}

		static YG_TIMECONTAINER s_TimeCurrent;

	private:

		static char s_Output[YG_LOG_SIZE];
		static char s_DayOfWeek[7][32];

	}; // struct Date

}; // namespace YoghurtGum

#endif
